<?php
namespace Weixin\Controller;

use Think\Controller;

// 本类由系统自动生成，仅供测试用途
class ClearTokenController extends Controller {
	
	
    public function clear(){ 
    	$access_token = 'ddd';
    	$time = 1333333331;
    	$this->createAccessTokenXml($access_token, $time);
    	$ticket = 'bbb';
    	$this->createApiTicketXml($ticket,$time);
    	$this->success('清除成功', U('/Admin/Index/mddConfig'));
    }
    
    /**
     *
     * @param $access_token 存放access_token
     * @param $time 存放access_token的时间
     */
    function createAccessTokenXml($access_token, $time) {
    	$doc = new \DOMDocument ( "1.0", "utf-8" );
    	$doc->formatOutput = true; // 设置可输出操作
    	$root = $doc->createElement ( "root" ); // 设置根节点
    	$root = $doc->appendChild ( $root ); // 添加根节点
    	$name = $doc->createElement ( "access_token" ); // 创建父节点name
    	$name = $root->appendChild ( $name ); // 把节点添加到menu节点的子节点
    	$name->appendChild ( $doc->createTextNode ( $access_token ) );
    
    	$type = $doc->createElement ( "time" ); // 创建父节点name
    	$type = $root->appendChild ( $type ); // 把节点添加到menu节点的子节点
    	$type->appendChild ( $doc->createTextNode ( $time ) );
    	$file_path = C ( 'wesetDir' ) . '/lib';
    	$doc->save ( $file_path . "/config/token.xml" );
    }
    
    
    /**
     *
     * @param $access_token 存放access_token
     * @param $time 存放access_token的时间
     */
    function createApiTicketXml($ticket, $time) {
    	$doc = new \DOMDocument ( "1.0", "utf-8" );
    	$doc->formatOutput = true; // 设置可输出操作
    	$root = $doc->createElement ( "root" ); // 设置根节点
    	$root = $doc->appendChild ( $root ); // 添加根节点
    	$name = $doc->createElement ( "ticket" ); // 创建父节点name
    	$name = $root->appendChild ( $name ); // 把节点添加到menu节点的子节点
    	$name->appendChild ( $doc->createTextNode ( $ticket ) );
    
    	$type = $doc->createElement ( "time" ); // 创建父节点name
    	$type = $root->appendChild ( $type ); // 把节点添加到menu节点的子节点
    	$type->appendChild ( $doc->createTextNode ( $time ) );
    	$file_path = C ( 'wesetDir' ) . '/lib';
    	$doc->save ( $file_path . "/config/api_ticket.xml" );
    }
}